package com.itheima.reggie;

import com.itheima.reggie.filter.LoginCheckFilter;
import com.itheima.reggie.filter.EmployeeCheckFilter;
import com.itheima.reggie.filter.UserCheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Slf4j
@SpringBootApplication
@ServletComponentScan
@EnableTransactionManagement
@EnableCaching
public class ReggieApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReggieApplication.class,args);
        log.info("启动成功");
    }

    @Bean
    public FilterRegistrationBean LoginCheckFilterFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new LoginCheckFilter());
        registration.addUrlPatterns("/*");
        registration.setName("loginCheckFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean EmployeeCheckFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new EmployeeCheckFilter());
        registration.addUrlPatterns("/employee/*");
        registration.setName("employeeCheckFilter");
        registration.setOrder(2);
        return registration;
    }

    @Bean
    public FilterRegistrationBean UserCheckFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new UserCheckFilter());
        registration.addUrlPatterns("/shoppingCart/*");
        registration.setName("userCheckFilter");
        registration.setOrder(3);
        return registration;
    }
}
